package com.irdstudio.efp.esb.service.impl.basicfn;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.basic.framework.core.constant.ESBConstant;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.TraceUtil;
import com.irdstudio.efp.esb.common.client.resp.EsbRespServiceBean;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.service.bo.req.basicfn.RscWarnLoanDatasReqBean;
import com.irdstudio.efp.esb.service.bo.resp.basicfn.RscWarnLoanDatasRespBean;
import com.irdstudio.efp.esb.service.client.ESBClientFactory;
import com.irdstudio.efp.esb.service.facade.basicfn.RscWarnLoanDatasService;
import com.irdstudio.efp.riskm.service.vo.RscWarnLoanVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 需求编号：【】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【】
 * 创建日期：【2019/11/19 17:21】
 * 功能描述：
 */
@Service("rscWarnLoanDatasService")
public class RscWarnLoanDatasServiceImpl implements RscWarnLoanDatasService, FrameworkService {
    private static Logger logger = LoggerFactory.getLogger(RscWarnLoanDatasServiceImpl.class);

    @Override
    public RscWarnLoanDatasRespBean applyRscWarnLoanDatas(RscWarnLoanDatasReqBean rscWarnLoanDatasReqBean) throws ESBException {
        logger.info("======>调用通用决策历史数据单个实时查询接口【40130012_08】开始<======");
        RscWarnLoanDatasRespBean rscWarnLoanDatasRespBean = null;
        try {
            EsbRespServiceBean recvBean = ESBClientFactory.buildClient()
                    .withBody(rscWarnLoanDatasReqBean)
                    .withTradeNo(ESBConstant.TRADE_NO_40130012)
                    .withScene(ESBConstant.SECNE_NO_08)
                    .create()
                    .sendAndReceive();
            if (EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(recvBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
                rscWarnLoanDatasRespBean = recvBean.getBody(RscWarnLoanDatasRespBean.class);
            } else {
                throw new ESBException(recvBean.getSysHead().getRetInfArry().get(0).getRetMsg());
            }
            logger.info("调用通用决策历史数据单个实时查询接口【40130012_08】结束，返回信息：" + JSONObject.toJSONString(rscWarnLoanDatasRespBean));
        } catch (Exception e) {
            logger.error("调用通用决策历史数据单个实时查询接口【40130012_08】出现异常：" + e.getMessage());
            throw new ESBException("调用通用决策历史数据单个实时查询接口【40130012_08】出现异常：" + e.getMessage());
        } finally {
            logger.info("======>调用通用决策历史数据单个实时查询接口【40130012_08】结束<======");
        }

        return rscWarnLoanDatasRespBean;
    }
}
